<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label">计划编号</label>
        <div class="layui-input-inline" style="width:500px">
            <input type="text" id="prpId" readonly="readonly" name="prpId" lay-verify="ord_id" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">计划完成天数</label>
        <div class="layui-input-inline" style="width:500px">
            <input type="text" name="planperiod" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item  ">
        <label class="layui-form-label">订单备注</label>
        <div class="layui-input-block" style="width:500px">
            <textarea placeholder="请输入内容" class="layui-textarea" name="Planremark" id="remark"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            $ = layui.$;
        var prpId = getQueryVariable("prpId");
        $("#prpId").val(prpId);
        //获取传递过来的参数
        function getQueryVariable(variable){
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                var pair = vars[i].split("=");
                if(pair[0] == variable){return pair[1];}
            }
            return(false);
        }

            $.ajax({
                type:"get",
                data:{
                    prpId:prpId,

                },
                url:"/getproduct",
                error:function(XMLHttpRequest,textStatus,errorThrown){
                    alert("执行失败了!");
                    alert(XMLHttpRequest.status);
                    alert(XMLHttpRequest.readyState);
                    alert("textStatus");

                },
                success:function(data){
                    if (data.code == 0){
                        var str="<option value=\"\" selected=\"\"></option>";
                        var mr = data.data.productionPlan;
                        $("#remark").val(mr.planremark);
                        $("#prpId").val(mr.prpId);
                        $("input[name='planperiod']").val(mr.planperiod);
                        form.render();
                    } else {
                        layer.alert(data.msg);
                        layer.open({
                            title:['确认消息'],
                            content: msg,
                            btn: ['确定'],
                            shadeClose: true,
                            yes: function(index, layero){
                                window.parent.closeSelf();
                            }
                        })
                        form.on('submit(saveBtn)', function (data){var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        })

                    }

                }

            })
        function closeSelf(){
            var i = window.parent.layer.getFrameIndex();
            window.parent.layer.close(i);
        }
        /*})*/
        //监听新增订单提交按钮
        form.on('submit(saveBtn)', function (data) {
            // layer.alert(JSON.stringify(data))
            $.ajax({
                type:"post",
                url:"/updateProductionplan",
                data:{
                    prpId:data.field.prpId,
                    Planremark:data.field.Planremark,
                    planperiod:data.field.planperiod,
                },
                success:function(data){
                    var msg = data.msg;
                    layer.open({
                        title:['确认消息'],
                        content: msg,
                        btn: ['确定'],
                        shadeClose: true,
                        yes: function(index, layero){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            window.parent.location.reload();//刷新父页面
                        }
                    })
                }

            })

            return false;
        });
        //数据验证
        form.verify({
            required:function (value) {
                if (new RegExp("^[a-zA-Z_\u4e00-\u9fa5\\s·]+$").test(value)) {
                    return '数量只能为数字';
                }
            }
        })

    });
</script>
</body>
</html>